package com.you.common.image;

import java.io.File;

import com.alibaba.simpleimage.ImageRender;
import com.alibaba.simpleimage.ImageWrapper;
import com.alibaba.simpleimage.SimpleImageException;
import com.alibaba.simpleimage.render.WriteParameter;
import com.alibaba.simpleimage.render.WriteRender;
import com.alibaba.simpleimage.util.ImageWriteHelper;

/**
 * fix writeRender BUG
 * @author yunpeng
 */
public class FixWriteRender extends WriteRender {

    public FixWriteRender(ImageWrapper image, String output, WriteParameter param) throws SimpleImageException{
        super(image, output, param);
    }

    @Override
    public ImageWrapper render() throws SimpleImageException {
        try {
            if (image == null) {
                image = imageRender.render();
            }

            ImageWriteHelper.write(image, stream, param);
        } catch (Exception e) {
            throw new SimpleImageException(e);
        }

        return null;
    }

}
